package com.zp.pullloadhelper;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;

/**
 * Created by izp on 2017/5/4.
 */

public final class ContentActivity extends BaseActivity {
    //final的Class这还是第一次见，
    /*即final类不能被继承，不能被覆盖，以及final类在执行速度方面比一般类快。*/
    private static final String EXTRA_FRAGMENT_TAG = "fragment_tag";
    @Override
    protected Fragment createFragment() {
        Intent intent = getIntent();
        try {
            //        从intent中获取fragment
            Class<? extends Fragment> fragmentClass = (Class<? extends Fragment>) intent.getSerializableExtra(EXTRA_FRAGMENT_TAG);
            return fragmentClass.newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static Intent getStartIntent(Context ctx, Class<? extends Fragment> cls) {
        Intent intent = new Intent(ctx, ContentActivity.class);
        intent.putExtra(EXTRA_FRAGMENT_TAG, cls);
        return intent;
    }


    public static Intent getStartIntent(Context ctx, Class<? extends Fragment> cls, Bundle bundle) {
        Intent intent = new Intent(ctx, ContentActivity.class);
        intent.putExtra(EXTRA_FRAGMENT_TAG, cls);
        intent.putExtras(bundle);
        return intent;
    }

    public static void go(Context context,Class<? extends Fragment> cls){
        Intent intent = new Intent(context,ContentActivity.class);
        intent.putExtra(EXTRA_FRAGMENT_TAG,cls);


    }
}
